/**    
* @Title: RightsController.java  
* @Package com.kaver.sso.web.controller.rest   
* @author roc   
* @date Aug 6, 2021 10:24:51 AM  
* @version V1.0  
* @copyright kaver 
*/
package com.kaver.sso.web.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kaver.sso.def.Result;
import com.kaver.sso.def.dto.RightsDto;
import com.kaver.sso.def.req.AddRightsReq;
import com.kaver.sso.def.req.DelRightsReq;
import com.kaver.sso.def.req.GroupRightsReq;
import com.kaver.sso.def.req.HasRightsReq;
import com.kaver.sso.def.req.RoleRightsReq;
import com.kaver.sso.def.req.SetRightsReq;
import com.kaver.sso.def.req.UpdateRightsReq;
import com.kaver.sso.def.req.UserRightsReq;
import com.kaver.sso.helper.UnAuth;
import com.kaver.sso.service.RightsService;

/**  
* @ClassName: RightsController  
* @Description: 权限 
* @author roc  
* @date Aug 6, 2021 10:24:51 AM  
*    
*/
@RestController
@RequestMapping("/api/rights")
public class RightsController {
    @Autowired
    RightsService rightsService;
    
    /**
     * 添加权限
     */
    @PostMapping("/addRights")
    public Result<Void> addRights(@RequestBody AddRightsReq req) {
        rightsService.addRights(req);
        return Result.createSuccess();
    }
    
    /**
     * 删除权限
     */
    @PostMapping("/delRights")
    public Result<Void> delRights(@RequestBody DelRightsReq req) {
        rightsService.delRights(req);
        return Result.createSuccess();
    }
    /**
     * 更新权限
     */
    @PostMapping("/updateRights")
    public Result<Void> updateRights(@RequestBody UpdateRightsReq req) {
        rightsService.updateRights(req);
        return Result.createSuccess();
    }
    
    /**
     * 角色设置权限
     */
    @PostMapping("/setRights")
    public Result<Void> setRights(@RequestBody SetRightsReq req) {
        rightsService.setRights(req);
        return Result.createSuccess();
    }
    /**
     * 获取组权限列表
     */
    @PostMapping("/groupRights")
    public Result<List<RightsDto>> groupRights(@RequestBody GroupRightsReq req) {
        return Result.createSuccess(rightsService.groupRights(req));
    }
    /**
     * 获取角色权限列表
     */
    @PostMapping("/roleRights")
    public Result<List<RightsDto>> roleRights(@RequestBody RoleRightsReq req) {
        return Result.createSuccess(rightsService.roleRights(req));
    }
    /**
     * 获取用户权限列表
     */
    @PostMapping("/userRights")
    public Result<List<RightsDto>> userRights(@RequestBody UserRightsReq req) {
        return Result.createSuccess(rightsService.userRights(req));
    }
    
    /**
     * 判断用户是否有权限
     */
    @UnAuth
    @PostMapping("/hasRights")
    public Result<Integer> hasRights(@RequestBody HasRightsReq req) {
        return Result.createSuccess(rightsService.hasRights(req));
    }
}
